/*
** server.h for zappy in /home/morgan_t/zappy-2015-2014s-suon_a/server/inc
** 
** Made by thomas morgant
** Login   <morgan_t@epitech.net>
** 
** Started on  Mon Jun 25 12:19:02 2012 thomas morgant
** Last update Thu Jul 12 16:42:06 2012 thomas morgant
*/

#ifndef _SERVER_H_
# define _SERVER_H_

#include <sys/time.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

# define	MAX_FD	42
# define	USAGE	"Usage : ./server -p [port] -x [width] -y [height] -n [team1] [team2] -c [nbr client] -t [time delay]\n"


typedef struct s_map
{
  int		width;
  int		height;
  int		tab[7];
  struct s_map	*next;
}		t_map;

typedef	struct	s_serv
{
  int	sock;
  int	port;
  int	width;
  int	height;
  char	*team1;
  char	*team2;
  int	client_in_team;
  int	time;
  t_map	*map;
}		t_serv;

typedef	struct	s_env
{
  int				i;
  int				t;
  int				end;
  int				cs;
  int				state;
  int				fd_max;
  fd_set			readfd;
  fd_set			writefd;
  struct	timeval		tv;
  struct	timezone	*ts;
}		t_env;


/*
** map
*/

void	load_elem(t_map **map, int width, int height, int elem);
int	check_case(t_map *map, int width, int height, int elem);
int	*get_elem_little_map(t_serv *serv, int *elem);
int	*get_elem(t_serv *serv, int *elem);
void	map(t_serv *serv);
void	create_map(t_map *temp);

/*
** utils
*/



/*
** check
*/

bool	check_params(t_serv *serv, int ac, char **av);
bool	check_port(t_serv *serv, int ac, char **av);
void	check_name(t_serv *serv, int ac, char **av);
void	check_height(t_serv *serv, int ac, char **av);
void	check_clients(t_serv *serv, int ac, char **av);
void	check_time(t_serv *serv, int ac, char **av);
void	check_width(t_serv *serv, int ac, char **av);

/*
** get
*/

void	get_params(t_serv *serv, int ac, char **av);

/*
** serv
*/

void	run(t_serv *serv, int ac, char **av);
void	init_serv(t_serv *serv);
void	init_struct_serv(t_serv *serv);
int	run_serv(t_serv *serv);
void	ig_serv(t_serv *serv, t_env *env);
int	look_for_fd(int fd_max);

/*
** 
*/



#endif /* _SERVER_H_ */
